package leetcode;

import java.util.ArrayList;
import java.util.Scanner;

/**
 * description:
 * author:zt
 * date:2021-08-07
 */
public class Solution {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            String s = sc.next();
            res[i] = test(s);
        }
        for (int i = 0; i < n-1; i++) {
            System.out.println(res[i]);
        }
        System.out.print(res[n-1]);
    }
    public static int test(String s){
        //系数
        int[] flag = new int[]{7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};
        char[] c = s.toCharArray();
        int sum = 0;
        ArrayList<Integer> unKnow = new ArrayList<>();
        for (int i = 0; i < c.length-1; i++) {
            if (c[i]!='*') sum += flag[i]*(c[i]-'0');
            else unKnow.add(i);
        }
        if (unKnow.isEmpty()) return 1;
        //计算余数
        int remain = 2;
        int[] flag2 = new int[]{1,0,10,9,8,7,6,5,4,3,2};
        if (c[17]>='0' && c[17]<'9') remain = flag2[c[17]-'0'];

        int ans = 0;
        if (unKnow.size()==1) {
            int k = unKnow.get(0);
            for (int i = 0; i < 10; i++) {
                if ((flag[k]*i+sum)%11==remain) ans++;
            }
        }else if (unKnow.size()==2){
            int k1 = unKnow.get(0);
            int k2 = unKnow.get(1);
            for (int i = 0; i < 10; i++) {
                for (int j = 0; j < 10; j++) {
                    if ((flag[k1]*i+flag[k2]*j+sum)%11==remain) ans++;
                }
            }
        }else if (unKnow.size()==3){
            int k1 = unKnow.get(0);
            int k2 = unKnow.get(1);
            int k3 = unKnow.get(2);
            for (int i = 0; i < 10; i++) {
                for (int j = 0; j < 10; j++) {
                    for (int d = 0; d < 10; d++) {
                        if ((flag[k1]*i+flag[k2]*j+flag[k3]*d+sum)%11==remain) ans++;
                    }
                }
            }
        }
        return ans;
    }
}
